<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String path = request.getContextPath();
	String basePath = request.getScheme()+"://" +request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/backstyle.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="js/getParentType.js"></script>
	<script type="text/javascript">
	$(function (){
		//初始化父类别
		getParentType();
		//异步提交表单信息
		//给表单绑定提交事件
		$("#form").submit(function (){
			//1.获取表单的数据
			var formData = $(this).serializeArray();
			console.log(formData);
			//2.封装
			var addData = new Object();
			//3.将表单数据存放进addData对象中
			for (var i = 0; i < formData.length; i++) {
				var name = formData[i].name;
				var value = formData[i].value;
				//将数据存放进data对象中
				addData[name] = value;
			}
			//发送请求
			$.ajax({
				url:"ProductTypeController/addProductType",
				type:"POST",
				contentType:"application/json",
				dataType:"JSON",
				data:JSON.stringify(addData),
				success:function (data){
					if(data.code == 200){
						//转跳到商品类别列表
						location.href="ProductTypeController/selectPage";
					}
				},
			});
			// 返回false不让表单自己提交，需要使用异步提交
			return false;
		})
	})
	</script>
</head>

<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">表单</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>添加商品类别信息</span></div>
    <form id="form">
    	<ul class="forminfo">
	    <li><label>商品类别名称</label><input name="name" type="text" class="dfinput" /><i>标题不能超过30个字符</i></li>
	    <li><label>父类别</label>
	    		<select name="pid" id="option">
	    			<option value="-1">新父类</option>
	    		</select>
	    </li>
	    <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认保存"/></li>
	    </ul>
    
    </form>
    </div>


<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div>
</body>
</html>

